package com.jeebey.mybatis.dialect;

import java.util.List;

import com.jeebey.mybatis.dialect.impl.DB2Dialect;
import com.jeebey.mybatis.dialect.impl.H2Dialect;
import com.jeebey.mybatis.dialect.impl.HSQLDialect;
import com.jeebey.mybatis.dialect.impl.InformixDialect;
import com.jeebey.mybatis.dialect.impl.MariadbDialect;
import com.jeebey.mybatis.dialect.impl.MysqlDialect;
import com.jeebey.mybatis.dialect.impl.OracleDialect;
import com.jeebey.mybatis.dialect.impl.PostgreSqlDialect;
import com.jeebey.mybatis.dialect.impl.SqlServer2012Dialect;
import com.jeebey.mybatis.dialect.impl.SqlServerDialect;
import com.jeebey.mybatis.dialect.impl.SqliteDialect;

public class DialectFactory {
	public static IDialect CURR_DIALECT_IMPL=new MysqlDialect();
	public static Dialect CURR_DIALECT=Dialect.mysql;
	
	public static IDialect createDialect(Dialect dialect){
		switch (CURR_DIALECT=dialect) {
		case mysql: 		CURR_DIALECT_IMPL = new MysqlDialect();break;
		case mariadb: 		CURR_DIALECT_IMPL = new MariadbDialect();break;
		case sqlite: 		CURR_DIALECT_IMPL = new SqliteDialect();break;
		case oracle: 		CURR_DIALECT_IMPL = new OracleDialect();break;
		case hsql: 			CURR_DIALECT_IMPL = new HSQLDialect();break;
		case sqlserver: 	CURR_DIALECT_IMPL = new SqlServerDialect();break;
		case sqlserver2012:	CURR_DIALECT_IMPL = new SqlServer2012Dialect();break;
		case db2: 			CURR_DIALECT_IMPL = new DB2Dialect();break;
		case postgresql: 	CURR_DIALECT_IMPL = new PostgreSqlDialect();break;
		case informix: 		CURR_DIALECT_IMPL = new InformixDialect();break;
		case h2: 			CURR_DIALECT_IMPL = new H2Dialect();break;
		default: 			CURR_DIALECT_IMPL = new MysqlDialect();
		}
		return CURR_DIALECT_IMPL;
	}
	
	public static boolean isAnyDialect(List<Dialect> dialects){
		if(dialects==null) {return false;}
		for(Dialect _dialect:dialects){
			if(CURR_DIALECT==_dialect){
				return true;
			}
		}
		return false;
	}
}
